<?xml version="1.0"?>
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:axsl="http://www.w3.org/1999/XSL/TransformAlias"
  exclude-result-prefixes="xsl"
  version="1.0">

  <xsl:namespace-alias
	stylesheet-prefix="axsl"
	result-prefix="xsl"/>

  <xsl:output indent="yes"/>

  <xsl:template match="tests">

    <axsl:stylesheet
      xmlns:doc="http://xsltsl.org/xsl/documentation/1.0"
      exclude-result-prefixes="doc"
      version="1.0">

      <doc:chapter xmlns="">
	<chapterinfo>
	  <author>
	    <surname>Ball</surname>
	    <firstname>Steve</firstname>
	  </author>
	  <copyright>
	    <year>2001</year>
	    <holder>Steve Ball</holder>
	  </copyright>
	</chapterinfo>

	<title>XSLT Standard Library Test Suite</title>

	<section>
	  <title>About The Test Suite</title>

	  <para>This stylesheet tests the stylesheet modules contained in the XSLT Standard Library</para>
	</section>

	<section>
	  <title>Running The Tests</title>

	  <para>Process the <filename>test.xml</filename> file with the stylesheet <filename>test.xsl</filename> using your favourite XSLT processor.  The result is a text document.  When the tests fail they print a text message, so no news is good news!  Messages are also printed to the console, which is useful for finding those templates which are hanging.</para>
	</section>
      </doc:chapter>

      <xsl:apply-templates select="module" mode="include"/>

      <axsl:output method="text" encoding="UTF-8"/>

      <axsl:template match="tests">
	<axsl:message>Tests starting</axsl:message>
	<axsl:text>Running stylesheet tests&#10;&#10;</axsl:text>

	<xsl:apply-templates select="module" mode="call"/>
      </axsl:template>

      <axsl:template name="test">
	<axsl:param name="expect"/>
	<axsl:param name="result"/>
	<axsl:param name="description">(no description)</axsl:param>

	<axsl:if test="$expect != $result">
	  <axsl:text>&#10;Test </axsl:text>
	  <axsl:value-of select="$description"/>
	  <axsl:text> failed.&#10;Result was:&#10;</axsl:text>
	  <axsl:value-of select="$result"/>
	  <axsl:text>&#10;Result should have been:&#10;</axsl:text>
	  <axsl:value-of select="$expect"/>
	</axsl:if>
      </axsl:template>

    </axsl:stylesheet>
  </xsl:template>

  <xsl:template match="module" mode="include">
    <axsl:include href="{@name}.test.xsl"/>
  </xsl:template>

  <xsl:template match="module" mode="call">
    <axsl:call-template name="{@name}"/>
  </xsl:template>

</xsl:stylesheet>
